package com.forever.controller;


import com.forever.toolAndAgent.AiResult;
import dev.langchain4j.service.Result;
import com.forever.toolAndAgent.Assistant;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/hl")
@RestController
public class OpenAiOllamaHighToolController {

    private final Assistant assistant;

    public OpenAiOllamaHighToolController(Assistant assistant) {
        this.assistant = assistant;
    }
    @GetMapping("/getUserByChat")
    @ResponseBody
    public Object chat(@RequestParam(value = "prompt", defaultValue = "获取客户张三的信息")
                        String prompt) {
        Result<AiResult> result = assistant.chat(prompt);
        return switchReturnType(result);
    }

    @GetMapping("/getNumSum")
    public Object getNumSum( @RequestParam(value = "prompt", defaultValue = "1加2等于多少")
                                 String prompt) {
        Result<AiResult> result = assistant.chat(prompt);
        return  switchReturnType(result);
    }

    private Object switchReturnType(Result<AiResult> result) {
        if(CollectionUtils.isNotEmpty(result.content().getList())){
            return result.content().getList();
        }
        if(result.content().getAnswer()!=null){
            return result.content().getAnswer();
        }
        return null;
    }
}
